package com.http;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Author:杨洪波
 * Date:2014-3-29
 * for 云维项目，特殊情况
 */
public class MyHttpClient {
    private URL url;
    private HttpURLConnection urlConn;
    private String chartsetCoding;
	private String urlPrefix;
	public String request(String urlSuffix) {
		return request(urlSuffix,"");
	}
	 public String request(String urlSuffix,String param) {
         try {
                 url = new URL(urlPrefix+urlSuffix);
                 urlConn = (HttpURLConnection) url.openConnection();
                 urlConn.setRequestMethod("GET");
                 //urlConn.setDoOutput(true);
                 // String param = "action=mobile&mobile=" + mobile_number;
                 /*urlConn.getOutputStream().write(param.getBytes());
                 urlConn.getOutputStream().flush();
                 urlConn.getOutputStream().close();*/
                 InputStream in = urlConn.getInputStream();
                 BufferedReader br = new BufferedReader(new InputStreamReader(in));
                 StringBuilder tempStr = new StringBuilder();
                 String brs = null;
                 while ((brs = br.readLine()) != null) {
                         tempStr.append(brs + "\n");
                         // tempStr.append(brs);
                 }
                 String s = new String(tempStr.toString().getBytes(), "GBK");
                 System.out.println("MyHttpClient.request::return string:"+s);
                 return s;
         } catch (Exception e) {
                 e.printStackTrace();
         } finally {
                 if (urlConn != null)
                         urlConn.disconnect();
         }
         return null;
	 }
	public String getChartsetCoding() {
		return chartsetCoding;
	}
	public void setChartsetCoding(String chartsetCoding) {
		this.chartsetCoding = chartsetCoding;
	}
	public URL getUrl() {
		return url;
	}
	public void setUrl(URL url) {
		this.url = url;
	}
	public HttpURLConnection getUrlConn() {
		return urlConn;
	}
	public void setUrlConn(HttpURLConnection urlConn) {
		this.urlConn = urlConn;
	}
	public String getUrlPrefix() {
		return urlPrefix;
	}
	public void setUrlPrefix(String urlPrefix) {
		this.urlPrefix = urlPrefix;
	}
	 

}
